package com.yyx.app1.My_function.UI;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.yyx.app1.Data.testDate;
import com.yyx.app1.MyApp;
import com.yyx.app1.R;
import com.yyx.app1.tool.ImageTool;
import com.yyx.app1.ui.ImageShower_Activity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by yuexing on 2015/9/16.
 */
@EActivity(R.layout.activity_my)
public class My_Acitivity extends Activity {
    private MyApp app;
    @ViewById
    TextView activity_my_question,activity_my_appointment,activity_my_personname,activity_my_hospital;

    @ViewById
    ImageView itemview_portrait;

    @AfterViews
    public void init()
    {
        try {
            app = (MyApp) getApplication();
            if (app.getBossInfo() == null) {
                startActivity(new Intent(My_Acitivity.this, Login_Activity_.class));
            } else {
                Bundle tag = new Bundle();
                tag.putString("type", "URL");
                tag.putString("value", app.getBossInfo().getPortraitURL());
                ImageShower_Activity.setTagOnClickListener(itemview_portrait, this, tag);
                ImageLoader imageLoader = app.getBaseDataManager().getM_imageLoader();
                imageLoader.get(app.getBossInfo().getPortraitURL(), imageLoader.getImageListener(itemview_portrait, testDate.loadImageRes, testDate.defaultPortrait), ImageTool.dip2px(this, 80), ImageTool.dip2px(this, 80));
                activity_my_personname.setText(app.getBossInfo().getName());
                activity_my_hospital.setText("未填写医院");
            }
        }catch (Exception e)
        {
            Log.e("异常1511081419",e.toString());
        }
    }

    @Override
    protected void onRestart() {
        init();
        super.onRestart();
    }

    @Click
    public void home()
    {
        finish();
    }

    @Click
    public void my_outlogin()
    {
        ((MyApp)getApplication()).setBossInfo(null);
        startActivity(new Intent(My_Acitivity.this, Login_Activity_.class));
    }

    @Click
    public void activity_my_info()
    {
        startActivity(new Intent(My_Acitivity.this,PerfectUserNameInfo_Activity_.class));
    }

    @Click
    public void activity_my_appointment()
    {
        startActivity(new Intent(My_Acitivity.this,MyAppointment_Activity_.class));
    }

    @Click
    public void activity_my_question()
    {
        startActivity(new Intent(My_Acitivity.this,MyQuestion_Activity_.class));
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            home();
        }
        return true;
    }
}
